﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;

namespace BHair.kucunpandian
{
    public partial class frmkcpdtable : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmkcpdtable()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void btnselect_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(constr);
            try
            {
                conn.Open();
                string sql =string.Format( "SELECT [spid] as 商品编号,[spname] as 商品名称,[spkc] as 商品库存,[pdkc] as 盘点库存,[pdyg] as 盘点员工,[pdtime] as 盘点日期,[pdID] as 盘点单号 FROM [BHairDB].[dbo].[kcpd] where pdtime >='{0}' and pdtime<='{1}'",dtpbengin.Text,dtpend.Text);
                DataTable dt = new DataTable();
                SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
                sda.Fill(dt);
                dataGridView1.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public DataSet dayin()
        {
            SqlConnection conn = new SqlConnection(constr);
            
                conn.Open();
                string sql = string.Format("SELECT [spid] ,[spname] ,[spkc] ,[pdkc] ,[pdyg] ,[pdtime] ,[pdID]  FROM [BHairDB].[dbo].[kcpd] where pdtime >='{0}' and pdtime<='{1}'", dtpbengin.Text, dtpend.Text);
                DataTable dt = new DataTable();
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds,"kcpd");
                sda.Fill(dt);
                dataGridView1.DataSource = dt;

            return ds;
        }

        //打印
        private void btndy_Click(object sender, EventArgs e)
        {
            DevExpress.XtraReports.UI.XtraReport xr = new DevExpress.XtraReports.UI.XtraReport();
            xr.LoadLayout(AppDomain.CurrentDomain.BaseDirectory + @"bb\Reportkcpdmx.repx");
            xr.DataSource = dayin();
            xr.ShowPreview();

        }
        //样式设计
        private void button1_Click(object sender, EventArgs e)
        {
            DevExpress.XtraReports.UI.XtraReport xr = new DevExpress.XtraReports.UI.XtraReport();
            xr.LoadLayout(AppDomain.CurrentDomain.BaseDirectory + @"bb\Reportkcpdmx.repx");
            xr.Report.Name = "kcpd";
            xr.ShowDesignerDialog();
            xr.SaveLayout(AppDomain.CurrentDomain.BaseDirectory + @"bb\Reportkcpdmx.repx");
            xr.Dispose();
        }
    }
}
